Setting Compiler and Linker Options

You can choose the options Project Builder uses when it compiles and links your program. In the Build Attributes section of the Project Inspector, you can choose options and search paths that are used for all build targets. In the Makefile.postamble file, you can choose options that are used only for specific build targets.

Setting Compiler and Linker Options for All Build Targets

To set compiler and linker options for all build targets:

  1. Click the Project Inspector button in the project window, and choose Build Attributes from the pop-up menu at the top of the Inspector.
  2. Edit the fields Compiler Flags and Linker Flags.

Here are some useful compiler flags:

Flag Description
-ansi Uses strict ANSI C syntax.
-traditional Uses the traditional C syntax, described in Kernigan & Ritchie's The C Language.
-bsd Uses strict BSD syntax.
-pointer-arith Warns you if you use pointer arithmetic on a void pointer or a function pointer.
-finline-functions Makes all simple functions inline.
-pipe Uses pipes in place of temporary intermediate files.

Here are some useful linker flags:

Flag Description
-sectorder Orders the blocks in a specified section.
-undefined Specifies how undefined symbols are treated: as errors, warnings, or ignored.
-whyload Prints why each member of a library is loaded.
-ysym For a given symbol, prints the names of the files that reference it.
-Yn For the first n undefined symbols, prints the names of the files that referenced it.

Setting Search Paths

You can choose additional directories where the compiler and linker search for header files, frameworks, and libraries. This is useful when your project contains a library or framework that is not in one of the standard search paths.

To modify the search paths:

  1. Click the Project Inspector button in the project window, and choose Build Attributes from the pop-up menu at the top of the Inspector.
  2. Choose one of the following from the second pop-up menu on the Inspector: Library Search Order, Framework Search Order, or Header Search Order.

To add a directory to a search path:

To edit a directory in the search path:

These are the standard directories that Project Builder always searches. You cannot remove them from the search paths.

Type of File Search Order
Frameworks /Local/Library/Frameworks/
/System/Library/Frameworks/
Header files the project directory
/Local/Developer/Headers/
/System/Developer/Headers/
Libraries /lib
/usr/lib/
/usr/local/lib

Setting Optimization Levels

You can choose how much the compiler optimizes your code. By default, the optimization option is set to -O1 . Project Build uses the optimization level whenever you build the default, install, or profile targets.

To set the optimization options:

Here are some useful values for OPTIMIZATION_CFLAG :

Flag Description
-O0 No optimization.
-O or -O1 Performs the following optimizations: * Allocates variables to registers using its own judgement, and ignoring the register keyword. * Optimizes branches.
-O2 Performs all the optimizations that -O1 does, plus: * Eliminates common sub-expressions. * Performs strength reduction.
-O3 Performs all the optimizations that -O2 does, plus: * Unrolls loops.

Setting Debug Options

You can choose how much debugging information the compiler puts into your code. By default, the debug option is set to -g. Project Builder uses the debug options whenever you build the debug target.

To set the debug level level:

Here are some useful values for DEBUG_BUILD_FLAGS , if you're compiling for Mac OS X:

Flag Description
-g Produces general debug information.
-gstabs Produces debugging information in stabs format, without GDB extensions.
-gstabs+ Produces debugging information in stabs format, with GDB extensions.

Here are some useful values for DEBUG_BUILD_FLAGS , if you're compiling for Windows NT or Windows98:

Flag Description
-g1 Produces minimal degugging information, including information on functions and external variables.
-g or -g2 Produces all the debugging information that -g1 does, plus information on line numbers and internal variables.
-g3 Produces all the debugging information that -g1 does, plus information on macros.

Project Builder's debugger GDB lets you debug optimized code. This is useful if you're experiencing a bug that only appears when you optimize your code. By default, the debug target does not optimize. To debug an optimized project:

Setting Warning Options

You can choose which warnings the compiler displays. Project Build uses the warnings options whenever you build the default, install, degug, or profile targets. By default, it uses the -Wmost option which warns against the most common errors but not against other constructions that are reasonable in some situations.

To set the warning options:

For example, to add pointer arithmetic to the list of things the compiler warns you about, use the following:

WARNING_CFLAG = -Wall -Wpointer-arith

Here are some useful values for WARNING_CFLAG :

Flag Description
-Wpointer-arith Warns you if you use pointer arithmetic on a void pointer or a function pointer.
-Wstrict-prototypes Warns you if you define or declare a function without specifying its argument types.
-Wmissing-prototypes Warns you if you define a global function is defined without a prototype declaration.
-Winline Warns you if the cmpiler cannot inline a function which you declared as inline or which the optimizer tried to inline.

© 1999 Apple Computer, Inc.